<?php

namespace app\admin\controller;

use think\exception\ValidateException;
use app\model\Paybill;
use app\model\Store;
use app\model\Member;
use app\model\Points;

class PaybillController extends Base
{
	function index()
	{
		$weid = weid();
		$page = input('post.page', 1, 'intval');
		$keyword = input('post.keyword', '', 'serach_in');
		$query = Paybill::where(['weid' => $weid]);

		if (!empty($this->sid)) {
			$query->where('sid', $this->sid);
		}
		if (!empty($this->ocid)) {
			$query->where('ocid', $this->ocid);
		}

		$res = $query->order('id desc')
			->paginate(getpage())
			->toArray();

		foreach ($res['data'] as &$vo) {
			$vo['cscl'] = [];
			$vo['storetitle'] = Store::getTitle($vo['sid']);
			$vo['username'] = Member::get_name($vo['uid']);
			$vo['pay_time'] = time_format($vo['pay_time']);
			$vo['points'] = Points::where('order_num_alias',$vo['bill_num_alias'])->find()?->toArray();
		}

		$data['data'] = $res;

		return $this->json($data);
	}

	function delete()
	{
		return $this->del(new Paybill());
	}
}
